package com.xuxueli.xxlrpc.remoting.invoker.route.impl;

import com.xuxueli.xxlrpc.remoting.invoker.route.XxlRpcLoadBalance;

import java.util.Random;
import java.util.TreeSet;

/**
 * @Author：YH
 * @Description：
 * @Date:Created in 2022/5/30 23:16
 */
public class XxlRpcLoadBalanceRandomStrategy extends XxlRpcLoadBalance {
    private Random random = new Random();

    @Override
    public String route(String serviceKey, TreeSet<String> addressSet) {
        // arr
        String[] addressArr = addressSet.toArray(new String[addressSet.size()]);

        // random
        String finalAddress = addressArr[random.nextInt(addressSet.size())];
        return finalAddress;
    }
}
